﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using OnlineJobPortal.Models;
using System.IO;
using System.Web.DataAccess;
using System.Web.Security;
using System.Web.Routing;

namespace JobPortal.Controllers
{
    public class AccountController : Controller
    {
        JobPortalEntities7 objEntities = new JobPortalEntities7();
        private IAccRepository account;
        public AccountController()
        {
        }
        public AccountController(IAccRepository account)
        {
            this.account = account;
        }
        public ActionResult Signup()
        {
            return View();
        }
        public ActionResult UploadFile()
        {
            return View();
        }
        public ActionResult UploadFile1()
        {
            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFileBase file = Request.Files[i];
                file.SaveAs(Server.MapPath(@"~\Gallery\" + file.FileName));
                Gallery g = new Gallery();
                g.ImagePath = file.FileName;
                objEntities.Galleries.Add(g);
                objEntities.SaveChanges();
            }
            
           
            return View("~/Views/Home/Index.cshtml");
        }
        public ActionResult AddUser( User user)
        {
            account.Save(user);
            return View("~/Views/Home/Index.cshtml");
        }
        public JsonResult CheckUserName(User u)
        {
            string email=Request["Email"];
            var result = from j in objEntities.Users
                        where j.Email == email
                        select j;
            if(result != null)
                    return Json(true, JsonRequestBehavior.AllowGet);
            else
                return Json(false, JsonRequestBehavior.AllowGet);
        }
        public ActionResult Logout()
        {
            FormsAuthentication.SignOut();
            Session["email"] = null;
            Session["userid"] = null;
            return View("~/Views/Home/Index.cshtml");
        }

    }
}
